<template>
  <section class="login-box">
    <el-row class="logo-nav" type="flex" align="middle">
      <img src="../../assets/img/logo.jpg" alt="" class="logo">
      <span>智慧缴费平台</span>
    </el-row>
    <el-row class="login-mid">
      <el-form :model="loginForm" :rules="rules" ref="loginForm" class="demo-ruleForm login-container">
        <h3 class="title">用户登录</h3>
        <el-form-item prop="username">
          <el-input type="text" v-model="loginForm.username" autofocus @keyup.enter.native="loginSubmit" auto-complete="off" placeholder="请输入登录手机号"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" v-model="loginForm.password" @keyup.enter.native="loginSubmit" auto-complete="off" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width:100%;" @click="loginSubmit" :loading="hasLoad">登录</el-button>
        </el-form-item>
        <router-link :to="{name: 'changePassword'}">
          <div class="login-pro clearfix">
            <span class="float-right pointer">忘记密码？</span>
          </div>
        </router-link>
      </el-form>
    </el-row>
  </section>
</template>

<script>
import { loginSystem } from 'api/login/index'
export default {
  data () {
    return {
      loginForm: {
        username: '', // 用户名
        password: '' // 密码
      },
      hasLoad: false,
      rules: { // 表单验证规则
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur,change' }
        ]
      }
    }
  },
  methods: {
    loginSubmit () { // 登录
      this.hasLoad = true
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          loginSystem(this.loginForm).then(res => {
            this.hasLoad = false
            window.localStorage.loginKey = res.data.loginKey
            window.localStorage.loginForm = JSON.stringify(this.loginForm)
            this.$router.push({name: 'home'})
          }).catch(res => {
            this.hasLoad = false
          })
        } else {
          this.hasLoad = false
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.login-box {
  width: 100%;
  height: 100%;
  padding-bottom: 180px;
  box-sizing: border-box;
  .logo-nav {
    width: 100%;
    height: 70px;
    padding-left: 30%;
    box-sizing: border-box;
    color: #5d5d5d;
    font-size: 20px;
    font-weight: bold;
    .logo {
      width: 50px;
      height: 50px;
      border-radius: 50%;
      margin-right: 18px;
    }
  }
  .logo-for {
    background: #447ed9;
    color: #fff;
  }
  .login-mid {
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
    background: url('../../assets/img/login.jpg') no-repeat fixed top/cover; 
  }
  .login-container {
    border-radius: 5px;
    background-clip: padding-box;
    margin: 0 auto;
    width: 390px;
    padding: 30px 35px 15px 35px;
    background: #fff;
    .title {
      margin: 0px auto 40px auto;
      text-align: center;
      color: #505458;
    }
    .login-pro {
      font-size: 12px;
      margin-bottom: 20px;
      margin-top: -5px;
      color: #194979;
      .pointer {
        text-decoration: underline;
      }
    }
  }
}
</style>